#pragma once

#include <iostream>
#include <string>

#include "oj_view.hpp"
#include "oj_model.hpp"
#include "../comm/log.hpp"
#include "../comm/util.hpp"

namespace dsh_control
{
    using namespace dsh_log;
    using namespace dsh_util;
    using namespace dsh_model;
    using namespace dsh_view;

    class Control
    {
    private:
        Model model_;
        View view_; 
    public:
        Control(){}
        ~Control(){}
        // 根据题目构建网页
        bool AllQuestions(std::string* html)
        {
            bool ret = true;
            std::vector<struct Question> all;
            if (model_.GetAllQuestions(&all))
            {
                // 获取所有题目成功，将所有的题目构建成网页
                view_.AllExpandHtml(all, html);
            }
            else
            {
                *html = "获取题目失败，形成题目列表失败";
                ret = false;
            }
            return ret;
        }
        // 获取某个题目的网页
        bool Question(const std::string& number, std::string* html)
        {
            bool ret = true;
            struct Question q;
            if (model_.GetOneQuestion(number, &q))
            {
                // 获取某题成功，构建网页
                view_.OneExpandHtml(q, html);
            }
            else
            {
                *html = "获取的指定题目 " + number + " 不存在";
                ret = false;
            }
            return ret;
        }
    };
}